package com.debao.quartz.task;


import cn.hutool.core.date.DateUtil;
import com.debao.common.constant.Constants;
import com.debao.system.domain.Coach;
import com.debao.system.domain.CourseCard;
import com.debao.system.domain.Statistic;
import com.debao.system.service.*;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 统计讲师的课程和学员数量
 */
@Component("statisticTask")
public class StatisticTask {

    @Resource
    private ICoachService coachService;

    @Resource
    private IStatisticService statisticService;

    @Resource
    private IUserCardService userCardService;

    @Resource
    private ISysUserService sysUserService;

    /**
     * 统计（每天凌晨1点定时）
     */
    public void statistic() {
        // 前一天的日期
        String beforeDate = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1));
        // 教练数量
        int coachNum = coachService.totalCount(beforeDate);
        //会员数量
        int vpiNum = userCardService.totalCount(beforeDate);
        //注册人数
        int userRegisterNum = sysUserService.countRegister(beforeDate);
        //总入账金额
        int totalMoney = statisticService.totalMoney(beforeDate);
        // 插入统计数据
        statisticService.insertStatistic(new Statistic().setDate(beforeDate).setTotalCoach(coachNum).setTotalMember(vpiNum).setTotalSign(userRegisterNum).setTotalMoney(totalMoney));
    }


}
